<template>
  <div>
    <el-form :model="form" ref="form" :rules="rules" label-width="100px" class="demo-ruleForm">
      <el-form-item label="姓名" prop="name" >
        <el-input type="age" v-model="form.name" auto-complete="off"></el-input>
      </el-form-item>
      <el-form-item label="年龄" prop="age" >
        <el-input type="age" v-model.number="form.age" auto-complete="off"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm('form')">提交</el-button>
        <el-button @click="resetForm('form')">重置</el-button>
        <el-button>新增</el-button>
      </el-form-item>
    </el-form>

  </div>
</template>
<script>
export default {
  data() {
    return {
      form: {
        age: ""
      },
      rules: {
        name: [
          { required: true, message: "姓名不能为空" },
        ],
        age: [
          { required: true, message: "年龄不能为空" },
          { type: "number", message: "年龄必须为数字值" }
        ]
      }
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          alert("submit!");
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    }
  }
};
</script>

<style>
.demo-ruleForm {
  width: 400px;
}
</style>
